package com.qingzhou.web.service.util;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.fastjson2.JSON;
import com.qingzhou.system.service.ISysDictDataService;
import com.qingzhou.web.service.RegionService;
import org.noear.solon.Solon;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class RegionUtil {
    public static String getRegion(String regionCodesArrayStr){
        boolean typeJSONArray = JSONUtil.isTypeJSONArray(regionCodesArrayStr);
        if(typeJSONArray){
            RegionService regionService = Solon.context().getBean(RegionService.class);
            Map<String, String> regionMap = regionService.getRegionMap();

            List<String> regionCodes = JSON.parseArray(regionCodesArrayStr, String.class);
            List<String> collect = regionCodes.stream().map(item -> regionMap.get(item)).collect(Collectors.toList());
            return CollUtil.join(collect,"/");
        }
        return regionCodesArrayStr;
    }
}
